package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;

import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.Scanner;

public class AddNoteController implements Initializable {

    @FXML
    private Button showSchedule;

    @FXML
    private Button searchRommTable;

    @FXML
    private Button SearchTecherTable;

    @FXML
    private Button ClassNote;

    @FXML
    private Button newNote;

    @FXML
    private Button deleteNote;

    @FXML
    private ChoiceBox<String> selectCourse;

    @FXML
    private Button addNote;

    @FXML
    private TextArea content;

    @FXML
    private TextField title;
    @FXML
    private Label hint;

    String xuehao;


    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        hint.setVisible(false);


        //得到学生学号
        try {
            Scanner input=new Scanner(new File("src/res/info.txt"));
            while (input.hasNext())
            {
                xuehao=input.next();
            }
            input.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        selectCourse.getItems().addAll(MysqlConn.getCourseListOnly(xuehao));
    }

    @FXML
    void addNewNote(ActionEvent event) {

        String t=title.getText();
        String cont=content.getText();
        String cname=selectCourse.getValue();
        if(MysqlConn.addNote(xuehao,cname,t,cont)==1) hint.setVisible(true);
        else {
            hint.setText("添加失败！");
            hint.setVisible(true);
        }
        title.clear();
        content.clear();
    }

    /*
=================================================================以下是界面转换====================================================================
     */
    @FXML
    void SwitchToDeletePage(ActionEvent event) {
        SceneManager.SwitchToDeleteNotePage(event);
    }

    @FXML
    void SwitchToNewNotePage(ActionEvent event) {
        SceneManager.SwitchToAddNotePage(event);
    }

    @FXML
    void SwitchToNotePage(ActionEvent event) {
        SceneManager.SwitchToNotePage(event);
    }

    @FXML
    void SwitchToSearchRoomTtblePage(ActionEvent event) {
        SceneManager.SwitchToSearchRoomTtblePage(event);
    }

    @FXML
    void SwitchToSearchTeacherTtblePage(ActionEvent event) {
        SceneManager.SwitchToSearchTeacherTtblePage(event);
    }
    @FXML
    void showSchedulePage(ActionEvent event) {
        SceneManager.SwitchToSchedulePage(event);
    }



}
